package com.ry.est.controller;

import com.ry.est.annotations.TokenUser;
import com.ry.est.common.controller.BaseController;
import com.ry.est.dto.CommonResult;
import com.ry.est.dto.SimpleOrderDTO;
import com.ry.est.entity.Users;
import com.ry.est.req.SubmitOrderRequest;
import com.ry.est.service.MaintainOrderService;
import com.ry.est.service.TokenService;
import com.ry.est.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 订单控制器
 * @author ry
 * @since 2021-11-10 10:10
 **/
@RestController
public class MaintainOrderController extends BaseController {
    @Autowired
    private MaintainOrderService maintainOrderService;
    @Autowired
    private TokenService tokenService;

    @PostMapping("/api/order/maintain/submit")
    public CommonResult<SimpleOrderDTO> submitOrder(
            @Valid SubmitOrderRequest submitOrderRequest,
            @TokenUser Users users
//            ,BindingResult bindingResult
    ){
        //不用bindingResult
//        if (bindingResult.hasErrors()){
//            //数据检验不通过
//        }
        //String token = request.getHeader("token");
        //Users userInfoByToken = tokenService.getUserInfoByToken(token);
        SimpleOrderDTO orderDTO = maintainOrderService.submitOrder(users, submitOrderRequest);
        
        return ResultUtil.success(orderDTO);
    }
}
